<?php

namespace App\Http\Controllers;

use App\Club;
use App\ClubLeader;
use Illuminate\Http\Request;

class ClubLeaderController extends Controller
{
    public function index()
    {
        $leaders = ClubLeader::latest('created_at')->Paginate(8);
        return view('Club.clubLeaders',compact('leaders'));
    }

    public function create()
    {
        $clubs = Club::all();
        return view('CLub.addClubLeader',compact('clubs'));
    }

    public function store(Request $request)
    {
        $rules = [
            'leader_name' => 'required',
            'phone' => 'required'
        ];
        $this->validate($request, $rules);

        $clubLeader = new ClubLeader;
        $clubLeader->create([
            'leader_name' => $request->get('leader_name'),
            'password' => bcrypt('123456'),
            'phone' => $request->get('phone'),
            'club_id' => 1
        ]);
        return redirect()->route('clubLeader.index');
    }

    public function destroy($id)
    {
        ClubLeader::destroy($id);
    }
}
